class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None



def getIntersectionNode(headA: ListNode, headB: ListNode) -> ListNode:

    pointerA = headA
    pointerB = headB

    while pointerA != pointerB:

        pointerA = pointerA.next if pointerA else headB
        pointerB = pointerB.next if pointerB else headA

    return pointerA